-- CALC_CAVE_BONUS_10

-- 计算怪物巢穴副本奖励
-- @param user    玩家对象
-- @param args    奖励计算参数
-- @param grade   副本难度
-- @param layer   地牢层数
return function(user, args, grade, layer)
    -- caution：如果修改该公式，服务器请一并修改

    -- 获取地牢难度系数
    local dugeonId = DungeonM.getDungeonId();
    if dugeonId == nil then
        dugeonId = user.dbase:query("currentDungeon");
    end
    local layerFix = DungeonAreaM.query(dugeonId, "layer_fix");
    -- grade : 副本难度
    -- layer : 地牢层数
    local fixCo, attack, magic = 0, 0, 0;
    local randSeed  = DungeonM.getRandSeed("DUNGEON_CAVE10");
    local randSeed2 = DungeonM.getRandSeed("DUNGEON_CAVE10");
    local arr = {};

    if grade == INSTANCE_GRADE_HARD then
        fixCo  = 200;
        attack = 2;
        arr    = { { ["rank"] = 5, ["amount"] = 1, ["ratio"] = 100, }, };    -- 随机5级宝物×1
    elseif grade == INSTANCE_GRADE_DIFFICULT then
        fixCo  = 150;
        attack = 1;
        arr    = { { ["rank"] = 4, ["amount"] = 1, ["ratio"] = 100, }, };    -- 随机4级宝物×1
    elseif grade == INSTANCE_GRADE_NORMAL then
        fixCo = 100;
        arr   = { { ["rank"] = 3, ["amount"] = 1, ["ratio"] = 100, }, };    -- 随机3级宝物×1
    else
        fixCo = 50;
        arr   = { { ["rank"] = 1, ["amount"] = 1, ["ratio"] = 100, },       -- 随机1级宝物×1
            { ["rank"] = 2, ["amount"] = 1, ["ratio"] = 100, }, };    -- 随机2级宝物×1
    end

    local ret = {};

    if fixCo > 0 then
        -- 探索点奖励
        table.insert(ret, { 2, "search_point", FormulaM.invoke("CALC_SEARCH_POINT_COST", fixCo, layer, layerFix), });
    end

    if attack > 0 then
        -- 属性奖励
        table.insert(ret, { 2, "attack", attack, });
    end

    if magic > 0 then
        -- 属性奖励
        table.insert(ret, { 2, "magic", magic, });
    end

    if #arr > 0 then
        -- 物品奖励
        local bonus = fetchElemBySeed(arr, randSeed);
        local equipArr = ItemM.getEquipByRank(bonus["rank"]);
        local classId  = FormulaM.invoke("FETCH_BY_RAND", equipArr, randSeed2);
        table.insert(ret, { 1, classId, bonus["amount"], });
    end

    return ret;
end